<html>
<head>
	<meta charset='utf-8' />
	<title>商户注册</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#Content,#Nav_bottom,#Back_Btn{width:98%;margin:0 auto}

			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#Content,#Nav_bottom,#Back_Btn{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body style='padding:0;margin:0'>



	<!-- 1 Content容器 -->
	<div id='Content' style=''>


		<img src="../Public/Image/base.png" alt="暂无图片" id='Banner' onerror='this.src="../Public/Image/base.png"' style='width:100%;' />

		<!--编辑或添加商户信息-->
		<div id='Store_Main_SubArea'>
			<h2 style='text-align:center;color:blue'>商户注册</h2>

			<div style='margin:10px auto;display:flex' id='Register_AreaSelect'>
				<div style='width:100px;text-align:right'>所属地域：</div>
				<div style='flex:1'>
					<select id="Province"></select>
					<select id="City"></select>
					<select id="County"></select>
					<div style='color:red'>注：地区注册后不可修改</div>
				</div>
			</div>



			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>商户名称：</div>
				<div style='flex:1'><input id='Register_Name' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>联系电话：</div>
				<div style='flex:1'><input id='Register_Phone' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>Q Q：</div>
				<div style='flex:1'><input id='Register_Qq' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>微信：</div>
				<div style='flex:1'><input id='Register_Wx' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>商户地址：</div>
				<div style='flex:1'><input id='Register_Addr' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>商户描述：</div>
				<div style='flex:1'><textarea id="Register_Info" style='width:90%;height:150px;resize:none' ></textarea></div>
			</div>


			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>店铺封面：</div>
				<div style='width:150px'>
					<input type="file" id='Register_File'  />
				</div>
			</div>

			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>验证码　：</div>
				<div style='flex:1;display:flex;height:30px'>
					<div style='width:80px'>
						<input id='Register_Code' style='height:100%;width:80px' />
					</div>
					<div style='flex:1;padding-left:10px;'>
						<img src="interface.php?type=code" id='Register_CodeImg' style='height:100%;width:90px' alt="点击" onclick='ChangeCode(this)'>
					</div>
				</div>
			</div>

			<div style='text-align:center;margin:20px auto'>
				<button id='Register_SubBtn'>提交</button>
			</div>
		</div>


	</div><!-- 1 Content容器结束 -->




</body>
</html>

<script src='../Public/jquery.js'></script>
<script src='../Public/fun.js'></script>

<script>
	var after_url = 'interface.php';
	var BannerTmp = '';
	var OpenCityObj;	//保存开通城市数据容器
	var StatusSetObj; 	//保存状态集合容器



	GetStatusSet(function(StatusSet){		//### 从localStorage，upyun获取状态集合，并定期更新
		if(/^{.*}$/.test(StatusSet)){
			StatusSetObj = JSON.parse(StatusSet);
			var CheckName = 'city_open';
			var le = localStorage.OpenCityExpire;
											//检测状态集合中指定字段是否过期
			var res = CheckStatusIsExpire(StatusSetObj,CheckName,le);	
			if(res == 'err'){
				localStorage.OpenCity = '';		//清空本地开通城市数据
			}
											//获取并填充城市数据
			CityInit(OpenCityObj,Province,City,County,function(){},12342349);

		}else{
			C('获取状态集合失败 in line 128');
			JumpError('../error.html?t=400012');	//400012 获取状态集合失败
		}
	});







	//选择图片并显示，及保存到临时变量中
	SelectOrViewImg('Register_File','Banner',function(file){
		if(file != 'err'){
			BannerTmp = file;
		}else{
			A('文件选择出现异常!');
		}
	});



	//添加或编辑商户信息提交
	$('#Register_SubBtn').click(function(){
		//### 检测验证码
		var Register_Code = ChangeChar($('#Register_Code').val().trim());
		Field_Check(/.+/,Register_Code,'js验证码不得为空!');

		var Register_Name = ChangeChar($('#Register_Name').val().trim());
		Field_Check(/^.{3,20}$/,Register_Name,'js商户名长度为3-20个字符!');

		var Register_Phone = ChangeChar($('#Register_Phone').val().trim());
		Field_Check(/^[1-9][0-9]{6,11}$/,Register_Phone,'js电话格式不正确!');
	
		var Register_Qq = ChangeChar($('#Register_Qq').val().trim());
		Field_Check(/^[1-9][0-9]{4,14}$|^$/,Register_Qq,'jsQQ号不正确!');

		var Register_Wx = ChangeChar($('#Register_Wx').val().trim());
		Field_Check(/^[a-zA-z0-9_-]{3,30}$|^$/,Register_Wx,'js微信号格式不正确!');

		var Register_Addr = ChangeChar($('#Register_Addr').val().trim());
		Field_Check(/^.{1,50}$|^$/,Register_Addr,'js地址长度不超过50个字符!');

		var Register_Info = ChangeChar($('#Register_Info').val().trim());
		Field_Check(/^.{1,300}$/,Register_Info,'js商户描述不得为空且不得超过300字符!');
	
		var Register_County = ChangeChar($('#County').find('option:selected').val().trim());



		var ProvinceName = ChangeChar($('#Province').find('option:selected').text().trim());
		var CityName = ChangeChar($('#City').find('option:selected').text().trim());
		var CountyName = ChangeChar($('#County').find('option:selected').text().trim());
		var CityFullName = ProvinceName+"-"+CityName+"-"+CountyName;



		//Notice('请求处理中......');

		var formData = new FormData();
		formData.append('code',Register_Code); 
		formData.append('name',Register_Name); 
		formData.append('phone',Register_Phone); 
		formData.append('info',Register_Info); 
		formData.append('county',Register_County); 
		formData.append('CityFullName',CityFullName); 

		
		if(BannerTmp){
			formData.append('banner',BannerTmp); //添加文件
		}
		if(Register_Qq){
			formData.append('qq',Register_Qq); 
		}
		if(Register_Wx){
			formData.append('wx',Register_Wx); 
		}
		if(Register_Addr){
			formData.append('addr',Register_Addr); 
		}


		var type = 'StoreInfoAddOrEdit';
		formData.append('type',type); 
		formData.append('openid',localStorage.openid); 



		Ajax_FormData2(formData,after_url,function(res){
			C(res);
			$('#Register_CodeImg').trigger('click');	//变换验证码
			if(res && (/^{"id".*}$/.test(res) || /^{.*}$/.test(res))){
				A('注册成功，等待审核！');
				sessionStorage.StoreInfo = res;
				location.replace('index.html');
			}else{
				switch(res){
					case 'err1':
						A('验证码不正确!');
					break;
					case 'err7':
						A('数据没有任何改动!');
					break;
					default:
						A('注册系统异常，请稍再试!');
					break;
				}
			}
		});

	});

</script>